package com.todo.event.activity.application.handler.dynamicwords;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.todo.event.activity.common.enums.EventActivityDynamicWordEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;

import java.util.List;
import java.util.Map;

/**
 * @author azhebuxing
 * @date 2025/1/13 16:46
 * @description
 */
@Slf4j
public abstract class AbstractDynamicWordsHandle {


    public Map<EventActivityDynamicWordEnum, Object> handle(List<EventActivityDynamicWordEnum> dynamicWords) {
        if (CollectionUtils.isEmpty(dynamicWords)) {
            return Maps.newHashMap();
        }
        if (match(dynamicWords)) {
            try {
                Map<EventActivityDynamicWordEnum, Object> result = doHandle(dynamicWords);
                log.info("AbstractDynamicWordsHandle#handle dynamic words success, dynamicWords:【{}】, result:【{}】", JSONObject.toJSONString(dynamicWords), JSONObject.toJSONString(result));
                return result;
            } catch (Exception ex) {
                log.error("AbstractDynamicWordsHandle#handle dynamic words error, dynamicWords:【{}】", JSONObject.toJSONString(dynamicWords), ex);
            }
        }
        return Maps.newHashMap();
    }


    protected abstract boolean match(List<EventActivityDynamicWordEnum> dynamicWords);

    protected abstract Map<EventActivityDynamicWordEnum, Object> doHandle(List<EventActivityDynamicWordEnum> dynamicWords);
}
